var user_info=JSON.parse(localStorage.user_info||'{}');
var pinggujigou=null;
var main = new Vue({
	el: '#main',
	data: {
		ip:localStorage.ip,
		loading:'',
		pagNamb:0,
		isActive: 1,
		oldMenName:"",//老人姓名
		response_0:[],
		hospitalName:user_info.hospitalName,//评估机构
		pinggujg:'',
		pingguriqi:'',
		pglxxz:'',//评估类型
		pinggyrenyuan:'',
		pinggujgname:'',//评估机构name
		wenhua:{
			'22': '大学本科结业 ',
			'28': '大学普通班毕业',
			'16': '硕士研究生肄业',
			'49': '技工学校肄业',
			'46': '职业高中肄业 ',
			'70': '初级中学教育 ',
			'12': '博士研究生结业 ',
			'19': '研究生班肄业 ',
			'20': '大学本科 ',
			'47': '技工学校毕业 ',
			'18': '研究生班结业 ',
			'23': '大学本科肄业',
			'83': '小学肄业',
			'33': '大学专科肄业 ',
			'42': '中等专科结业 ',
			'10': '技工学校结业 ',
			'48': '技工学校结业 ',
			'71': '初中毕业 ',
			'90': '其他 ',
			'81': '小学毕业 ',
			'80': '小学教育 ',
			'62': '普通高中结业',
			'63': '普通高中肄业',
			'21': '大学本科毕业 ',
			'17': '研究生班毕业 ',
			'30': '大学专科教育 ',
			'13': '博士研究生肄业 ',
			'43': '中等专科肄业 ',
			'45': '职业高中结业 ',
			'60': '普通高级中学教育 ',
			'41': '中等专科毕业 ',
			'15': '硕士研究生结业',
			'14': '硕士研究生毕业',
			'11': '博士研究生毕业 ',
			'61': '普通高中毕业 ',
			'31': '大学专科毕业 ',
			'40': '中等职业教育 ',
			'43': '初中肄业 ',
			'32': '大学专科结业 ',
			'44': '职业高中毕业 ',
		},
		pglx:{
			ycfx_pg:'压疮风险评估',
			yy_pg:'抑郁评估',
			wxzxfx_pg:'误吸窒息风险评估',
			yyfx_pg:'营养风险评估',
			"ddfx-frat_pg":'跌倒风险FRAT评估',
			ddfx_pg:'跌倒风险评估',
			lngnzkzh_pg:'老人功能状况评估',
			zn_pg:'智能评估',
			zlnl_pg:'自理能力评估'
		}
	},
	methods:{
		openurl:function(info,nub){
			sessionStorage.pgoldinfo=JSON.stringify(info);
			if(nub==1){
				window.location.href='jieguo.html';
			}else{
				window.location.href='oldweihu.html';
			}
		},
		onScroll:function(ref){//滚动加载
			if(this.$refs[ref].scrollTop+this.$refs[ref].clientHeight >= this.$refs[ref].scrollHeight-2){
				if(this.isActive == 1){
					waiting(this.oldMenName,this.pglxxz,this.pinggujg,this.pingguriqi,this.pinggyrenyuan,this.pagNamb)
				}
			}
		},
		resettype:function(){
			this.pinggujgname=this.pglxxz=this.pinggujg=this.pingguriqi=this.pinggyrenyuan='';
		}
	},
	watch: {
	    oldMenName:function(){
		    	this.loading="";
		    	this.response_0=[]
		    	waitingName(this.oldMenName,this.pglxxz,this.pinggujg,this.pingguriqi,this.pinggyrenyuan)
	    },
	    pglxxz:function(){
	    	 	this.response_0=[]
		    	this.loading="";
		    	waitingName(this.oldMenName,this.pglxxz,this.pinggujg,this.pingguriqi,this.pinggyrenyuan)
	    },
	    pinggujg:function(){
	    	 	this.response_0=[]
		    	this.loading="";
		    	waitingName(this.oldMenName,this.pglxxz,this.pinggujg,this.pingguriqi,this.pinggyrenyuan)
	    },
	    pingguriqi:function(){
	    	 	this.response_0=[]
		    	this.loading="";
		    	waitingName(this.oldMenName,this.pglxxz,this.pinggujg,this.pingguriqi,this.pinggyrenyuan)
	    },
	    pinggyrenyuan:function(){
	    	 	this.response_0=[]
		    	this.loading="";
		    	waitingName(this.oldMenName,this.pglxxz,this.pinggujg,this.pingguriqi,this.pinggyrenyuan)
	    }
	}
})
//ASSESS_WAIT
var timeid=null;
function waitingName(nameold,pglxx,pinggujg,pingguriqi,pinggyrenyuan){
//	console.log("chuan1"+nameold);
	clearTimeout(timeid);
	main.response_0.length=0;
	timeid=setTimeout(function(){waiting(nameold,pglxx,pinggujg,pingguriqi,pinggyrenyuan)},1000)	
}
function waiting(oldname,pglxxz,pinggujg,pingguriqi,pinggyrenyuan,pagNamb){
	main.isActive=0;
	if(!main.loading){
		main.loading="正在加载 . . .";
		ajaxPost(
			Url.ASSESS_FINDVATE,
			{
				"cxtj":oldname||'',
				"pglx":pglxxz||'',
				"pgjgid":pinggujg||'',
				"pgrq":pingguriqi||'',
				"pageSize":'5',
				"pageIndex":pagNamb||'0',
				"pgr":user_info.name,
				"type":pinggyrenyuan||'1'
			},
			function(data){
				document.getElementById("main").setAttribute("style","display: block;");
				if(data.status==1){
					pagNamb>=0 ? main.pagNamb+=1:'';
					for(var i=0;i<data.response.length;i++){
						main.response_0.push(data.response[i])
					}
					if(data.response.length == 0&&main.pagNamb==0){
						main.loading="未查询到评估信息。。。";
					}else if(data.response.length<5){
						main.loading="没有更多了。。。"
					}else{
						main.loading='';
					}
					main.isActive=1;
				}
			},
			function(){
				main.loading="";
			}
		)
	}
}
/*
function waiting(oldname,pageNo){
	document.getElementById("main").setAttribute("style","display: block;");
	if(!main.loading){
		main.loading="正在加载 . . .";
		ajaxPost(
			Url.ASSESS_WAIT,
			{
				"pageNo":pageNo||"0",
				"pageSize":"10",
				"name":oldname||""
			},
			function(data){
				document.getElementById("main").setAttribute("style","display: block;");
				console.log(data)
				if(data.status==1){
					main.pagNamb+=1;
					for(var i=0;i<data.response.length;i++){
						main.response_0.push(data.response[i])
					}
					if(data.response.length == 0){
						main.loading="未查询到老人信息。。。";
						var r=confirm("请确认输入信息是否正确或者请新增老人信息，是否新增老人信息？");
						if (r==true){
						  	alert("You pressed OK!");
						}else{
						  	alert("You pressed Cancel!");
						}
					}else if(data.response.length<10){
						main.loading="没有更多了。。。"
					}else{
						main.loading='';
					}
				}
			},
			function(){
				main.loading="";
			}
		)
	}
}*/
waiting("")

var pglx = [
	{
		value: 'ycfx_pg',
		text: '压疮风险评估'
	},
	{
		value: 'yy_pg',
		text: '抑郁评估'
	},
	{
		value: 'wxzxfx_pg',
		text: '误吸窒息风险评估'
	},
	{
		value: 'yyfx_pg',
		text: '营养风险评估'
	},
	{
		value: 'ddfx-frat_pg',
		text: '跌倒风险FRAT评估'
	},
	{
		value: 'ddfx_pg',
		text: '跌倒风险评估'
	},
	{
		value: 'lngnzkzh_pg',
		text: '老人功能状况评估'
	},
	{
		value: 'zn_pg',
		text: '智能评估'
	},
	{
		value: 'zlnl_pg',
		text: '自理能力评估'
	},
];
var pgrenyuan = [
	{
		value: '1',
		text: '本人评估'
	},
	{
		value: '2',
		text: '全部评估'
	}
];
function chushi($, doc) {
	$.init();
	$.ready(function() {
		var _getParam = function(obj, param) {
			return obj[param] || '';
		};
		//评估类型
		var userPicker = new $.PopPicker();
		userPicker.setData(pglx);
		var showUserPickerButton = doc.getElementById('pinggutype');
		showUserPickerButton.addEventListener('tap', function(event) {
			userPicker.show(function(items) {
				console.log(items[0].value)
				main.pglxxz=items[0].value
			});
		}, false);
		//评估人员
		var userPicker2 = new $.PopPicker();
		userPicker2.setData(pgrenyuan);
		var showUserPickerButton2 = doc.getElementById('pingurenyan');
		showUserPickerButton2.addEventListener('tap', function(event) {
			userPicker2.show(function(items) {
				console.log(items[0].value)
				main.pinggyrenyuan=items[0].value
			});
		}, false);
		//评估机构
		var userPicker3 = new $.PopPicker();
		userPicker3.setData(pinggujigou);
		var showUserPickerButton3 = doc.getElementById('pinggujg');
		showUserPickerButton3.addEventListener('tap', function(event) {
			userPicker3.show(function(items) {
				main.pinggujg=items[0].value
				main.pinggujgname=items[0].text
			});
		}, false);
		
	});
	var riqi = $('#riqixz')[0];
	riqi.addEventListener('tap', function() {
		var _self = this;
		var optionsJson = this.getAttribute('data-options') || '{}';
		var options = JSON.parse(optionsJson);
		_self.picker = new $.DtPicker(options);
		_self.picker.show(function(rs) {
			main.pingguriqi=rs.text
			_self.picker.dispose();
			_self.picker = null;
		});
	}, false);
};
ajaxPost(
	Url.ASSESS_GETJG,
	{},
	function(data){
		if(data.status=='1'){
			pinggujigou=JSON.parse(JSON.stringify(data.response).replace(/pgjg_ID/g,'value').replace(/pgjg/g,'text'));
		}
		chushi(mui, document)
	}
)